<template>
    <d2-container :filename="filename">
        <template slot="header">
            <el-form
                    :inline="true"
                    ref="form"
                    size="mini"
                    style="margin-bottom: -18px;">
                <el-form-item>
                    <el-button type="primary" @click="goto('/goods/attr/add')" icon="el-icon-plus">添加</el-button>
                </el-form-item>
            </el-form>
        </template>
        <el-table v-loading="listLoading" :data="tableData"
                  :stripe="true"
                  border fit highlight-current-row style="width: 100%;">
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <el-table-column label="编号" width="150" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.id }}</span>
                </template>
            </el-table-column>
            <el-table-column label="属性名称" min-width="180" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.name }}</span>
                </template>
            </el-table-column>
            <el-table-column label="商品类型" width="180" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.product_attribute_category_id }}</span>
                </template>
            </el-table-column>
            <el-table-column label="检索方式" width="120" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.search_type }}</span>
                </template>
            </el-table-column>
            <el-table-column label="分类筛选样式" width="120" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.filter_type }}</span>
                </template>
            </el-table-column>
            <el-table-column label="属性录入方式" width="180" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.input_type }}</span>
                </template>
            </el-table-column>
            <el-table-column label="支持手动新增" width="150" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.hand_add_status }}</span>
                </template>
            </el-table-column>
            <el-table-column label="可选值列表" min-width="180" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.input_list }}</span>
                </template>
            </el-table-column>
            <el-table-column label="排序" width="80" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.sorted }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" min-width="180" align="center" fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini" icon="el-icon-edit"
                               @click="handleEdit(scope.row)"
                               type="primary">编辑
                    </el-button>

                    <el-button size="mini" icon="el-icon-delete"
                               @click="handleDelete(scope.row.id, scope.row.name)"
                               type="danger">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
    </d2-container>
</template>

<script>
  import { deleteProductAttr, pageProductAttr } from '@/api/goods/attr'

  export default {
    name: 'goods-attr-list',
    data () {
      return {
        filename: __filename,
        tableData: [],
        listLoading: false,
        queryParam: {
          current: 1,
          size: 10,
          type: this.$route.query.type,
          cid: this.$route.query.cid
        }
      }
    },
    created () {
      this.getList()
    },
    methods: {
      getList () {
        this.listLoading = true
        pageProductAttr(this.queryParam).then(res => {
          this.tableData = res.records
          this.listLoading = false
        })
      },
      goto (path) {
        this.$router.push(path)
      },
      handleEdit () {

      },
      handleDelete (id, name) {
        this.$confirm('此操作将永久删除【' + name + '】属性,是否继续?', '友情提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteProductAttr(id).then(res => {
            if (res) {
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
            } else {
              this.$message({
                type: 'warning',
                message: '删除失败'
              })
            }
          })

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    }

  }
</script>

<style scoped>

</style>
